<?php
namespace app\admin\controller;
use app\admin\model\AuthModel;
use app\admin\model\LocationModel;
use app\admin\model\UserModel;
use think\Request;

class Userlocation extends Common
{
    protected function get_where()
    {
        $where = [];
        $model = new UserModel();
        $key = Request::instance()->param('keyword');
        if($key != ''){
            $where['nickname'] = ['like','%'.$key.'%'];
        }
        $user_list = $model->where($where)->select();
        $user = [];
        foreach ($user_list as $value){
            $user[] = $value['id'];
        }
        $where = [];
        if(count($user) > 0){
            $where['user_id'] = ['in',$user];
        }
        $location_id = Request::instance()->param('location_id');
        if($key != 0){
            $where['location_id'] = $location_id;
        }
        return $where;
    }
    protected function index_assign(){
        $model = new LocationModel();
        $list = $model->field('id,name')->select()->toArray();
        $this->assign('location',$list);
    }
    public function filter_list($list)
    {
        foreach ($list as &$value){
            $user = UserModel::get(['id'=>$value['user_id']]);
            $value['user'] = $user['nickname'];
            $location = LocationModel::get(['id'=>$value['location_id']]);
            $value['location'] = $location['name'];
        }
        return $list;
    }
}
